package org.example.fancystudy.basic;

/**
 * @author chaigq
 * @version 1.0
 * @date 2023/9/19 10:19
 */
public class BasicTest2 {
    private int id;
    private int age;
    private String name;

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }
    //看看我的equals方法有问题吗，完全没毛病
    //当三个属性相等我们就可以认为是同一个人了
    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (this == obj) {
            return true;
        }
        if (this.getClass() != obj.getClass()) {
            return false;
        }
        BasicTest2 user = (BasicTest2) obj;
        if (this.getAge() == user.getAge() &&
                this.getId() == user.getId() &&
                this.getName().equals(user.getName())) {
            return true;
        }
        return false;
    }
    //hashcode我们使用默认的
    @Override
    public int hashCode() {
        return super.hashCode();
    }
}

class Test {
    public static void main(String[] args) {
        BasicTest2 user1=new BasicTest2();
        user1.setAge(22);
        user1.setId(1);
        user1.setName("老田");

        BasicTest2 user2=new BasicTest2();
        user2.setAge(22);
        user2.setId(1);
        user2.setName("老田");

        System.out.println(user1.equals(user2));
        System.out.println("user1 hashcode="+user1.hashCode());
        System.out.println("user2 hashcode="+user2.hashCode());
    }
}
